

# -*- coding:utf-8 -*-
class Solution:
    def LastRemaining_Solution(self, n, m):
        if not n or not m:
            return -1
        a = list(range(n))
        j = 0
        while len(a)!=1:
            t = (j + m - 1) % n
            # t 是 index 下标
            a.pop(t)
            n -= 1
            j = t
        return a[0]


s=Solution()
print(s.LastRemaining_Solution(8,3))